package com.general.message.push;

import com.general.message.push.domain.SimpleMessage;

import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 简单消息推送
 * @author 王首都
 * @date 2024/01/06
 */
public abstract class SimpleMessagePush {

    private final static ExecutorService logExecutorService = Executors.newSingleThreadExecutor();

    /**
     * 推送消息
     * @param message           消息内容对象
     * @param enablePushLog     是否记录推送日志
     */
    public void pushMessage(SimpleMessage message, boolean enablePushLog) {
        boolean success = this.doMessagePush(message);
        if (enablePushLog) {
            this.doLog(message, success);
        }
    }

    /**
     * 消息推送
     * @param message 消息内容
     * @return boolean
     */
    public abstract boolean doMessagePush(SimpleMessage message);

    public void pushMessage(SimpleMessage message) {
        pushMessage(message, true);
    }

    public void doLog(SimpleMessage message, boolean pushSuccess) {
        if (Objects.nonNull(message)) {
            logExecutorService.execute(() -> {

            });
        }
    }

}